package com.geektime.hello;

import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.URLUtil;
import cn.hutool.http.HttpStatus;
import org.apache.commons.io.IOUtils;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * @Author: DRevelation
 * @Date: 2020/12/21 9:21
 */
public class UrlFileNotFoundDemo {
    public static void main(String[] args) throws IOException {

        String matUrl = "http://dbxz1-hw.ahtv.cn/20201218191852/1b0ecf6369ec4ef8b5fd50ffa4063c49.mp4";
        URL url = new URL(matUrl);
//        InputStream is = URLUtil.getStream(url);
//        byte[] bytes = IOUtils.toByteArray(url);
        InputStream is = null;
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        int status = connection.getResponseCode();
        if (status >= HttpStatus.HTTP_BAD_REQUEST) {
            is = connection.getErrorStream();
        } else {
            is = connection.getInputStream();
        }
        System.out.println("bytes.length = " + is.available());
    }
}
